import scrapy


class CarSpider(scrapy.Spider):
    name = 'car' # 爬取汽车之家
    allowed_domains = ['https://car.autohome.com.cn/price/brand-15.html']
    start_urls = ['https://car.autohome.com.cn/price/brand-15.html']

    def parse(self, response):
        print("爬取汽车之家...")
        name_list = response.xpath('//div[@id="brandtab-1"]//div[@class="main-title"]/a/text()')
        price_list = response.xpath('//div[@id="brandtab-1"]//div[@class="main-lever-right"]//span/text()')
        print(name_list)
        for i in range(len(name_list)):
            # print(name_list[i], ' ：', price_list[i])
            # <Selector xpath='//div[@id="brandtab-1"]//div[@class="main-title"]/a/text()' data='宝马3系'>  ： <Selector xpath='//div[@id="brandtab-1"]//div[@class="main-lever-right"]//span/text()' data='29.99-39.99万'>

            print(name_list[i].extract(), ' ：', price_list[i].extract())
            # 宝马3系  ： 29.99-39.99万

